package com.aqa.ms.thread;

/**
 * @author Administrator
 * 同时启动三个线程，第一个打印a，第二个打印b，第三个打印c
 * 连续打印6个abc
 */
public class SeqPrint {

	private static volatile boolean boolA = false;
	private static volatile boolean boolB = false;
	private static volatile boolean boolC = false;

	private static volatile boolean breakA = true;
	private static volatile boolean breakB = true;
	private static volatile boolean breakC = true;


	public static void main(String[] args) {

		boolA = true;
		Thread threadA = new Thread(() ->   {
			int a = 1;
			while(breakA) {
				while(boolA && a <= 6) {
					System.out.println("a");
					boolA = false;
					boolB = true;
					a++;
				}
				if(a>6) {
					breakA = false;
				}
			}
		});
		threadA.start();
		Thread threadB = new Thread(() ->   {
			int b = 1;
			while(breakB) {
				while(boolB && b <= 6) {
					System.out.println("b");
					boolB = false;
					boolC = true;
					b++;
				}
				if(b>6) {
					breakB = false;
				}
			}
		});
		threadB.start();
		Thread threadC = new Thread(() ->   {
			int c = 1;
			while(breakC) {
				while(boolC && c <= 6) {
					System.out.println("c");
					System.out.println("-------------------");
					boolC = false;
					boolA = true;
					c++;
				}
				if(c>6) {
					breakC = false;
				}
			}
		});
		threadC.start();
//		Thread.yield();

		try {
			threadC.join();
			threadB.join();
			threadA.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}






}
